import os
from tools.funciton import *
import requests
from time import sleep
from config import *


def sync_orders(filename):
    url = "https://apiv2.dingstock.net/express/jd/callback"
    orders = read_xlsx_file(os.path.join(DOWNLOAD_PATH, filename), 0)
    expressNos = read_xlsx_file(os.path.join(DOWNLOAD_PATH, filename), 1)
    s = 1
    for i in range(len(orders)):
        payload = json.dumps({
            "orderId": orders[i],
            "waybillCode": expressNos[i],
        })
        headers = {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'Content-Type': 'application/json',
            'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImxtNGV6a2VvIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNzE2OTc2OTAzfQ.dCgQKmIHQ2MFAk12foFq7d0BIl7RcDL3Wlqsetw6Gu0',
            'Accept': '*/*',
            'Host': 'dc-oa-dev-0703.dingstock.net',
            'Connection': 'keep-alive'
        }
        response = requests.request("POST", url, headers=headers, data=payload)
        print(response.text, s)
        s += 1
        sleep(0.2)


sync_orders('运单信息20250102100700279.xlsx')
